package cn.xpp011.distributedlocksdemo.service.impl;

import cn.xpp011.distributedlocksdemo.annotation.locks.DistributedLock;
import cn.xpp011.distributedlocksdemo.service.IService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @program: distributed-locks-demo
 * @description:
 * @author: xpp011
 * @create: 2022-03-05 22:15
 **/
@Service
public class ServiceImpl implements IService {

    private static final Logger log = LoggerFactory.getLogger(ServiceImpl.class);

    int i = 0, j = 0;

    @Override
    @DistributedLock(prefix = "my-", value = "test", keyTimeout = 3000L, retryCount = 0, paramLock = true)
    public String test(String s, int t, Object o) {
//        log.error("{} 执行方法, i:{}",Thread.currentThread().getName(), i++);
        log.error("i : {}", i++);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return s + "succeed";
    }

    @Override
    public void test(){
        log.error("j : {}", j++);
    }
}
